﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Core.Log;

namespace Core.Xml.Ogc.Ows
{
    class ResponsiblePartyType : IXmlType
    {
        public string IndividualName { get; set; }
        public string PositionName { get; set; }
        public ContactType ContactInfo { get; set; }
        public CodeType Role { get; set; }

        public XElement CreateXElement(System.Xml.Linq.XName elementName)
        {
            XElement responsibleParty = new XElement(elementName);

            bool check = false;

            if (!String.IsNullOrEmpty(IndividualName))
            {
                responsibleParty.Add(new XElement(Namespaces.OWS + "IndividualName", IndividualName));
                check = true;
            }
            if (!String.IsNullOrEmpty(PositionName))
            {
                responsibleParty.Add(new XElement(Namespaces.OWS + "PositionName", PositionName));
                check = true;
            }
            if (ContactInfo != null)
            {
                responsibleParty.Add(ContactInfo.CreateXElement(Namespaces.OWS + "ContactInfo"));
                check = true;
            }
            if (Role != null)
            {
                responsibleParty.Add(Role.CreateXElement(Namespaces.OWS + "Role"));
                check = true;
            }

            if (!check)
                Logger.GetInstance().Add(new BasicLog(LogPriority.WARNING, "ResponsibleParty Type element is empty, it should be removed."));

            return responsibleParty;
        }
    }
}
